package com.kinyx.framework.crawler;

import java.io.File;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.kinyx.framework.file.KFileReader;

public class KCrawler_Tester_0_main extends KCrawler_Tester_0_Super {

	@Before
	public void before() {
		this.toFile(false);
	}

	@Test
	public void fromFile() {
		final String bodyHtml = KFileReader.read(new File(this.filePath), this.CHARSET);
		final Document html = Jsoup.parseBodyFragment(bodyHtml);
		final Elements divs = html.select("div#publish");
		for (final Element div : divs) {
			final Elements tds = div.select("td");
			for (final Element td : tds) {
				if (td.html().contains("上市日期")) {
					final Elements spans = td.select("span");
					final Element span = spans.get(0);
					Assert.assertEquals("2016-08-05", span.html());
				}
			}
		}
	}

}
